package com.huihuiyun.huihuiyun.server.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.Map;

@Component
@Path("/hello")
@Slf4j
public class HelloService {
    @Context
    private UriInfo uriInfo;

    @Context
    HttpServletRequest httpServletRequest;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public Response get(@QueryParam("name") @DefaultValue("Mark") String name) {
        String clientIPAddress = httpServletRequest.getRemoteAddr();
        log.error("request ip address is:" + clientIPAddress);
        return Response.ok("hello, " + name).build();
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    public Response getData(Map data) {
        return Response.ok(data.toString()).build();
    }
}